package jnpf.common.enums.dify;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public enum DifyAITypeEnum {
    AI_HELP("1", "ai_help", "知识助手"),
    CHAT("2", "chat", "聊天助手"),
    AGENT_CHAT("3", "agent-chat", "agent聊天"),
    COMPLETION("4", "completion", "文本生成"),
    ADVANCED_CHAT("5", "advanced-chat", "chat流"),
    WORKFLOW("6", "workflow", "工作流");

    private final String code;
    private final String type;
    private final String description;

    DifyAITypeEnum(String code, String type, String description) {
        this.code = code;
        this.type = type;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getType() {
        return type;
    }

    public String getDescription() {
        return description;
    }

    public static List<String> getCodeList() {
        return Arrays.stream(values()).map(DifyAITypeEnum::getCode).collect(Collectors.toList());
    }

    public static List<String> getTypeList() {
        return Arrays.stream(values()).map(DifyAITypeEnum::getType).collect(Collectors.toList());
    }

    public static DifyAITypeEnum getByCode(String code) {
        return Arrays.stream(values())
                .filter(type -> type.getCode().equals(code))
                .findFirst()
                .orElse(null);
    }
    public static String getTypeByCode(String code) {
        DifyAITypeEnum typeEnum = getByCode(code);
        return typeEnum != null ? typeEnum.getType() : null;
    }
    // 新增方法：通过 type 获取 code
    public static String getCodeByType(String type) {
        return Arrays.stream(values())
                .filter(item -> item.getType().equals(type))
                .findFirst()
                .map(DifyAITypeEnum::getCode)
                .orElse(null);
    }
}
